﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineManagement.Web.userControl
{
    public partial class UCSowWeanedRecordSettings : BaseSowUserControl
    {
        protected Guid _sowId;
        protected int _childTotalCount;
        protected Guid _hybrizationRecordID;
        protected Guid _propagateRecordId;
        protected int hoggeryId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                 hoggeryId = HoggeryID;
                try
                {
                    lbBitID.Text = BitID;
                    lbPigpenName.Text = PigPenName;
                    lbSowType.Text = SowTypeName;
                    _sowId = SowID;
                    if (PropagateStateOrder != Order)
                    {
                        Response.Redirect("SowOperations.aspx");
                    }
                    lbChildPigType.Text = ChildPigType;
                    _childTotalCount = ChildTotalCount;
                    lbChildDayOld.Text = ChildDayOld.ToString();
                    lbChildCount.Text = _childTotalCount.ToString();
                    _hybrizationRecordID = HybridizationRecordID;
                    _propagateRecordId = PropagateRecordId;
                    BindDdlPigPen(HoggeryID);

                }catch(Exception ex){
                   log4net.ILog log= OnlineHoggeryLog.GetLog("userControl.UCSowWeanedRecordSettings");
                   log.Error(new Com.HoggeryLog() { HoggeryID = HoggeryID }, ex);
                   panError.Visible = true;
                   panContent.Visible = false;
                }
            }
        }

        private void BindDdlPigPen(int hoggeryId) {
            try
            {
                BLL.Dal.PigPen bllPB = new BLL.Dal.PigPen();
                System.Data.DataSet ds=  bllPB.GetAvailabltePigPens(hoggeryId);
                if(ds!=null&&ds.Tables.Count>0){
                    ddlPigPen.DataSource = ds;
                    ddlPigPen.DataTextField = "CustomizeID";
                    ddlPigPen.DataValueField="PigPenID";
                    ddlPigPen.DataBind();
                }
            }catch(Exception ex){
                throw ex;
            }
        }
    }
}